package com.module.base.widget.recyclerview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.module.base.R;

/**
 * @author bsnl_yanxuwen
 * @date 2020/4/23 12:11
 * Description :
 * 边界虚化
 */
public class RecyclerViewAlpha extends NestVerticalRecyclerView {

    private boolean alpha_top;
    private boolean alpha_left;
    private boolean alpha_right;
    private boolean alpha_bottom;


    public RecyclerViewAlpha(@NonNull Context context) {
        this(context, null);
    }

    public RecyclerViewAlpha(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RecyclerViewAlpha(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RecycleViewAlpha);
        alpha_left = typedArray.getBoolean(R.styleable.RecycleViewAlpha_alpha_left, false);
        alpha_right = typedArray.getBoolean(R.styleable.RecycleViewAlpha_alpha_right, false);
        alpha_top = typedArray.getBoolean(R.styleable.RecycleViewAlpha_alpha_top, false);
        alpha_bottom = typedArray.getBoolean(R.styleable.RecycleViewAlpha_alpha_bottom, false);
    }

    /**
     * 重写这个方法，返回值是0,去掉顶部阴影
     *
     * @return
     */
    @Override
    protected float getTopFadingEdgeStrength() {
        return alpha_top ? super.getTopFadingEdgeStrength() : 0;
    }

    /**
     * 重写这个方法，返回值是0,去底顶部阴影
     *
     * @return
     */
    @Override
    protected float getBottomFadingEdgeStrength() {
        return alpha_bottom ? super.getBottomFadingEdgeStrength() : 0;
    }

    /**
     * 重写这个方法，返回值是0,去左顶部阴影
     *
     * @return
     */
    @Override
    protected float getLeftFadingEdgeStrength() {
        return alpha_left ? super.getLeftFadingEdgeStrength() : 0;
    }

    /**
     * 重写这个方法，返回值是0,去底右部阴影
     *
     * @return
     */
    @Override
    protected float getRightFadingEdgeStrength() {
        return alpha_right ? super.getRightFadingEdgeStrength() : 0;
    }
}
